package com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.apache.tomcat.jni.OS;

import com.entity.EasyBuy_news;
import com.sun.org.apache.regexp.internal.recompile;

public class EasyBuy_newsDaoImpl extends BaseDao<EasyBuy_news> implements EasyBuy_newsDao {
	
	Connection conn = null;
	PreparedStatement ps = null;
	ResultSet rs = null;
	
	
	@Override
	public List<EasyBuy_news> selectShowAllInfo() {
		List<EasyBuy_news> list = new ArrayList<EasyBuy_news>();
		try {
			conn = getConnection();
			ps = conn.prepareStatement("SELECT * FROM easybuy_news");
			rs = ps.executeQuery();
			while (rs.next()) {
				EasyBuy_news news = new EasyBuy_news();
				news.setId(rs.getInt("id"));
				news.setTitle(rs.getString("title"));
				news.setContent(rs.getString("content"));
				news.setCreateTime(rs.getString("createtime"));
				list.add(news);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			closeAll(conn, ps, rs);
		}
		return list;
	}


	@Override
	public EasyBuy_news idSelectInfo(int id) {
		EasyBuy_news news = null;
		try {
			conn = getConnection();
			ps = conn.prepareStatement("SELECT * FROM easybuy_news where id = ?");
			ps.setObject(1, id);
			rs = ps.executeQuery();
			news = new EasyBuy_news();
			while (rs.next()) {
				news.setId(rs.getInt("id"));
				news.setTitle(rs.getString("title"));
				news.setContent(rs.getString("content"));
				news.setCreateTime(rs.getString("createtime"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			closeAll(conn, ps, rs);
		}
		return news;
	}


	@Override
	public String getTableName() {
		return "easybuy_news";
	}
	
}
